#PhpSwoole Dockerfile
ARG PHP_VERSION
FROM ${PHP_VERSION}
LABEL maintainer="Jhou Shuai <jhou.shuai@qq.com>" version="1.0" license="MIT" app.name="PhpSwoole"

ENV PHP_MEMORY_LIMIT 1G
ENV MAX_UPLOAD 50M
ENV PHP_MAX_FILE_UPLOAD 200M
ENV PHP_MAX_POST 100M
ENV PHP_INI_DIR /usr/local/etc/php
ENV TZ Asia/Shanghai
ENV APP_ENV=${APP_ENV:-"prod"}

#使用国内的源防止超时
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g" /etc/apk/repositories

# 基础配置
RUN apk update && apk add tzdata git curl vim \
    m4 autoconf make gcc g++ linux-headers \
    imagemagick-dev libmcrypt-dev zlib-dev libpng-dev libzip-dev libwebp-dev jpeg-dev libjpeg-turbo-dev freetype-dev \
    libintl icu icu-dev oniguruma oniguruma-dev openssl openssl-dev zip unzip tree protobuf curl-dev \
    yaml-dev


# 时区
RUN cp /usr/share/zoneinfo/${TZ} /etc/localtime && \
  echo "${TZ}" > /etc/timezone

# 扩展
RUN docker-php-ext-configure gd --with-webp=/usr/include  --with-jpeg=/usr/include --with-freetype=/usr/include
RUN docker-php-ext-install -j$(nproc) gd pdo_mysql opcache bcmath pcntl zip intl sockets

RUN pecl install redis-5.3.7 \
    && pecl install mongodb \
    && pecl install --configureoptions 'enable-sockets="yes" enable-openssl="yes" enable-http2="yes"  \
    enable-mysqlnd="yes" enable-swoole-json="yes" enable-swoole-curl="yes"' swoole \
    && pecl install xlswriter \
    && pecl install mcrypt \
    && pecl install imagick \
    && pecl install protobuf \
    && pecl install yaml \
    && docker-php-ext-enable redis mongodb swoole xlswriter mcrypt imagick protobuf yaml

# Configure php.ini
RUN php -v \
    && php -m \
    && php --ri swoole \
    && { \
        echo "upload_max_filesize=${MAX_UPLOAD}"; \
        echo "max_file_uploads=${PHP_MAX_FILE_UPLOAD}"; \
        echo "post_max_size=${PHP_MAX_POST}"; \
        echo "memory_limit=${PHP_MEMORY_LIMIT}"; \
        echo "date.timezone=${TZ}"; \
        echo "swoole.use_shortname=Off"; \
        echo "expose_php=Off"; \
        echo "cgi.fix_pathinfo=0"; \
    } | tee ${PHP_INI_DIR}/conf.d/99_overrides.ini

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer

RUN  apk del tzdata && \
     rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
     apk del .build-deps \
     && echo -e "\033[42;37m Build Completed :).\033[0m\n"

WORKDIR /var/www

# 端口
#EXPOSE 8501-8504
EXPOSE 8501

#ENTRYPOINT ["php", "/var/www/bin/hyperf.php", "start"]